package com.example.pro2;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class MainActivity extends Activity {
    Button button;
    ProgressBar bar1,bar2,bar3,bar4,bar5;
    ImageView iv1,iv2,iv3,iv4,iv5;
    int current=0;
    Handler handler=new Handler(){
    	public void handleMessage(Message msg) {
    		switch (msg.what) {
			case 1:
				if(current==100){
					iv1.setImageResource(R.drawable.gou);
					iv2.setImageResource(R.drawable.gou);
					iv3.setImageResource(R.drawable.gou);
					iv4.setImageResource(R.drawable.gou);
					iv5.setImageResource(R.drawable.gou);
				}
				bar1.setProgress(current);
				bar2.setProgress(current);
				bar3.setProgress(current);
				bar4.setProgress(current);
				bar5.setProgress(current);
				break;

			default:
				break;
			}
    	};
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initEvent();
    }


    private void initEvent() {
		// TODO Auto-generated method stub
		button.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new Thread(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						while(current<100){
						try {
							Thread.sleep(200);
							handler.sendEmptyMessage(1);
							current++;
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					  }
					}
				}).start();
			}
		});
	}


	private void initView() {
		// TODO Auto-generated method stub
		button=(Button) findViewById(R.id.button);
		bar1=(ProgressBar) findViewById(R.id.progressBar1);
		bar2=(ProgressBar) findViewById(R.id.progressBar2);
		bar3=(ProgressBar) findViewById(R.id.progressBar3);
		bar4=(ProgressBar) findViewById(R.id.progressBar4);
		bar5=(ProgressBar) findViewById(R.id.progressBar5);
		iv1=(ImageView) findViewById(R.id.iamgeView1);
		iv2=(ImageView) findViewById(R.id.iamgeView2);
		iv3=(ImageView) findViewById(R.id.iamgeView3);
		iv4=(ImageView) findViewById(R.id.iamgeView4);
		iv5=(ImageView) findViewById(R.id.iamgeView5);
		bar1.setMax(100);
		bar2.setMax(100);
		bar3.setMax(100);
		bar4.setMax(100);
		bar5.setMax(100);
	}


	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
